package sz.szsmk.citizencard.ui.adapter;

import android.content.Context;
import android.os.Build;

import androidx.annotation.RequiresApi;
import androidx.recyclerview.widget.RecyclerView;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import sz.szsmk.citizencard.R;
import sz.szsmk.citizencard.model.network.bean.response.AccumPointRes;

/**
 * author : hyt
 * date : 2019/8/16
 * description :
 */
public class SignInAdapter   extends RecyclerView.Adapter<SignInAdapter.MyViewHolder>{

    private Context context;
    private List<AccumPointRes.CreditInfoBean> pointList = new ArrayList<>();

    public SignInAdapter( Context context){
        this.context = context;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_signin, parent, false);
        return new MyViewHolder(view);
    }

    @RequiresApi(api = Build.VERSION_CODES.N)
    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        holder.tv_point.setText(Html.fromHtml("<font color='#00AAFF'>"+position+"</font> <font color='#637077'>积分</font>",Html.FROM_HTML_MODE_LEGACY));
    }

    @Override
    public int getItemCount() {
        return this.pointList.size();
    }


    public void setData(List<AccumPointRes.CreditInfoBean> pointList){
        if(pointList!=null){
            this.pointList.addAll(pointList);
            notifyDataSetChanged();
        }
    }

    public void clear() {
        pointList.clear();
        notifyDataSetChanged();
    }


    public class MyViewHolder extends RecyclerView.ViewHolder {

        TextView tv_title;
        TextView tv_time;
        TextView tv_point;

        MyViewHolder(View itemView) {
            super(itemView);

            TextView tv_title = itemView.findViewById(R.id.tv_title);
            TextView tv_time = itemView.findViewById(R.id.tv_time);
            TextView tv_point = itemView.findViewById(R.id.tv_point);
        }
    }
}
